import request from '@/utils/request'
import { otherFiltersItem } from '@/utils'
/**
 * 激活验收任务
 * @param {*} data
 * @returns
 */
export function postActiveTask(data) {
  return request({
    url: '/api/v1/shopAccept/activeTask',
    method: 'POST',
    data
  })
}

/**
 * 修改验收任务
 * @param {*} data
 * @returns
 */
export function saveAccept(data) {
  return request({
    url: '/api/v1/shopAccept',
    method: 'put',
    data
  })
}
/**
 * 报验资料审核
 * @param {*} data
 * @returns
 */
export function postShopAccept(data) {
  return request({
    url: '/api/v1/shopAccept/audit',
    method: 'POST',
    data
  })
}
/**
 * 安排验收
 * @param {*} data
 * @returns
 */
export function postArrangeAccept(data) {
  return request({
    url: '/api/v1/shopAccept/arrangeAccept',
    method: 'POST',
    data
  })
}
/**
 * 获取问题软装，硬装详情
 * @param {*} id
 * @param {*} acceptType
 * @returns
 */
export function getProblemDetailList(id, acceptType) {
  let url = `/api/v1/shopAccept/problemDetailList?id=${id}`
  if (acceptType) {
    url = `/api/v1/shopAccept/problemDetailList?id=${id}&acceptType=${acceptType.toUpperCase()}`
  }
  return request({
    url,
    method: 'GET'
  })
}
/**
 * 问题模板
 * @returns
 */
export function getDutyAndProblemlist() {
  return request({
    url: '/api/v1/configAcceptDuty/dutyAndProblemlist',
    method: 'GET'
  })
}
/**
 * 验收详情
 * @param {*} id
 * @returns
 */
export function getApplyDetail(id) {
  return request({
    url: `/api/v1/shopAccept/applyDetail/${id}`,
    method: 'GET'
  })
}
/**
 * 验收申请保存
 * @param {*} data
 * @returns
 */
export function postAddOrEdit(data) {
  return request({
    url: '/api/v1/shopAccept/addOrEdit',
    method: 'POST',
    data
  })
}
/**
 * 验收申请提交
 * @param {*} data
 * @returns
 */
export function postApplyCommit(data) {
  return request({
    url: '/api/v1//shopAccept/applyCommit',
    method: 'POST',
    data
  })
}
/**
 * 合并验收详情查询
 * @param  {any} ids
 * @returns
 */
export function postMergeTaskSelect(ids) {
  return request({
    url: '/api/v1/shopAccept/mergeTaskSelect',
    method: 'POST',
    data: ids.map(id => {
      return {
        id
      }
    })
  })
}
/**
 * 获取多条数据
 * @param {*} ids
 * @returns
 */
export function postSelectPage(ids) {
  const data = new FormData()
  const filtersRaw = []
  ids.forEach(e => {
    filtersRaw.push(otherFiltersItem('id', `[${ids.join(',')}]`, 'in'))
  })
  data.append('filtersRaw', JSON.stringify(filtersRaw))
  data.append('pageFlag', false)
  return request({
    url: '/api/v1/shopAccept/selectPage',
    method: 'POST',
    data,
    headers: {
      'Permission-perCode': 'checkhard',
      'Permission-App': 'slm'
    }
  }).then(res => {
    return res.data.records
  })
}
/**
 * 合并提交
 * @param {*} data
 * @returns
 */
export function postMergeTaskSubmit(data) {
  return request({
    url: '/api/v1/shopAccept/mergeTaskSubmit',
    method: 'POST',
    data
  })
}
/**
 * 验收执行本次验收区域
 * @param {*} accId
 * @returns
 */
export function getSeriesByAccId(accId) {
  return request({
    url: `/api/v1/acceptAreaSeriesDetail/getSeriesByAccId/${accId}`,
    method: 'GET'
  })
}
/**
 * 非本次验收区域查询
 * @param {*} accId
 * @returns
 */
export function getUnSeriesByAccId(accId) {
  return request({
    url: `/api/v1/acceptAreaSeriesDetail/getUnSeriesByAccId/${accId}`,
    method: 'GET'
  })
}
/**
 * 验收区域保存
 * @param {*} data
 * @returns
 */
export function postBatchEdit(data) {
  return request({
    url: '/api/v1/acceptAreaSeriesDetail/batchEdit',
    method: 'POST',
    data
  })
}
/**
 * 获取附件配置
 * @returns
 */
export function postConfigAttachmentTemplate() {
  const data = new FormData()
  data.append('filtersRaw', JSON.stringify([otherFiltersItem('belongModel', 'SHOP_DECORATION', '=')]))
  return request({
    url: '/api/v1/configAttachmentTemplate/page',
    method: 'POST',
    data
  })
}
/**
 * 保存问题明细
 * @param {*} data
 * @returns
 */
export function postSaveProblem(data, type) {
  return request({
    url: `/api/v1/shopAccept/saveProblem/${type}`,
    method: 'POST',
    data
  })
}
/**
 * 保存评估
 * @param {*} data
 * @returns
 */
export function postAcceptAssess(data, id) {
  return request({
    url: `/api/v1/shopAccept/acceptAssess/${id}`,
    method: 'POST',
    data
  })
}
/**
 * 获取评分详情
 * @param {*} scoreNature
 * @param {*} unitCode
 * @param {*} decorationTaskCode
 * @returns
 */
export function postConstUnitAssessScoreDetail(scoreNature, unitCode, decorationTaskCode) {
  const data = new FormData()
  data.append('paramsRaw', JSON.stringify({ scoreNature }))
  const filtersRaw = []
  if (!/,/.test(unitCode)) {
    filtersRaw.push(otherFiltersItem('unitCode', unitCode, '='))
  } else {
    filtersRaw.push(otherFiltersItem('unitCode', `[${unitCode}]`, 'in'))
  }
  filtersRaw.push(otherFiltersItem('decorationTaskCode', decorationTaskCode, '='))

  // if (!/,/.test(decorationTaskCode)) {
  //   filtersRaw.push(otherFiltersItem('decorationTaskCode', decorationTaskCode, '='))
  // } else {
  //   filtersRaw.push(otherFiltersItem('decorationTaskCode', `[${decorationTaskCode.join(',')}]`, '='))
  // }
  data.append('filtersRaw', JSON.stringify(filtersRaw))
  return request({
    url: '/api/v1/constUnitAssessScore/detail',
    method: 'POST',
    data
  })
}
/**
 * 提交评估
 * @param {*} data
 * @returns
 */
export function postCommitAcceptAssess(data, id) {
  return request({
    url: `/api/v1/shopAccept/commitAcceptAssess/${id}`,
    method: 'POST',
    data
  })
}
/**
 * 关联装修任务
 * @param {*} accId
 * @returns
 */
export function getSelectByAccId(accId) {
  return request({
    url: `/api/v1/shopDecoration/selectByAccId/${accId}`,
    method: 'GET'
  })
}
/**
 * 区域及系列
 * @param {*} acceptId
 * @returns
 */
export function postAcceptAreaSeriesDetailPage(accId) {
  return request({
    url: `/api/v1/acceptAreaSeriesDetail/selectByAccId/${accId}`,
    method: 'GET'
  })
}
/**
 * 验收问题明细
 * @param {*} id
 * @returns
 */
export function getProblemList(id) {
  return request({
    url: `/api/v1/shopAccept/problemList/${id}`,
    method: 'GET'
  })
}
/**
 * 问题明细详情
 * @param {*} acceptDutyId
 * @returns
 */
export function postAcceptProblemDetailPage(acceptDutyId) {
  const data = new FormData()
  data.append('filtersRaw', JSON.stringify([
    otherFiltersItem('acceptDutyId', acceptDutyId, '=')
  ]))
  data.append('pageFlag', false)
  return request({
    url: '/api/v1/acceptProblemDetail/page',
    method: 'POST',
    data
  })
}

/**
 * 核对结案详情
 * @param {*} id
 * @param {*} acceptEndType
 * @returns
 */
export function postdDecorationClosedType(id, acceptEndType) {
  return request({
    url: '/api/v1/shopAccept/checkCloseType',
    method: 'POST',
    data: {
      id,
      acceptEndType
    }
  })
}
/**
 * 软装问题明细
 * @param {*} id
 * @returns
 */
export function getSoftProblemList(id) {
  return request({
    url: `/api/v1/shopAccept/softProblemList/${id}`,
    method: 'GET'
  })
}
/**
 * 软装详情
 * @param {*} id
 * @returns
 */
export function getSoftDetail(id) {
  return request({
    url: `/api/v1/shopAccept/softDetail/${id}`,
    method: 'GET'
  })
}
/**
 * 软装验收报告确定
 * @param {*} data
 * @returns
 */
export function postCommitSoftDetail(data, type) {
  return request({
    url: `/api/v1/shopAccept/commitSoftDetail/${type}`,
    method: 'POST',
    data
  })
}
/**
 * 获取软装验收申请详情
 * @param {*} id
 * @returns
 */
export function getSoftApplyDetail(id) {
  return request({
    url: `/api/v1/shopAccept/softApplyDetail/${id}`,
    method: 'GET'
  })
}
/**
 * 获取客户编码
 * @param {*} shopCode
 * @returns
 */
export function getCustomerCode(shopCode) {
  const data = new FormData()
  const filtersRaw = [
    otherFiltersItem('code', shopCode, '=')
  ]
  data.append('filtersRaw', JSON.stringify(filtersRaw))
  return request({
    url: '/select-service/api/v1/shop/page',
    method: 'POST',
    data
  }).then(res => {
    if (res.data.records.length === 0) {
      return Promise.reject(res)
    }
    return res.data.records[0].customerCode
  })
}
/**
 * 根据客户编码获取业务账号
 * @param {*} customerCode
 * @returns
 */
export function postAccountPage(customerCode) {
  const data = new FormData()
  data.append('pageFlag', false)
  data.append('filtersRaw', JSON.stringify([otherFiltersItem('customerCode', customerCode, '=')]))
  return request({
    url: '/select-service/api/v1/account/page',
    method: 'POST',
    data,
    headers: {
      'permission-code': 'checkhard', // 页面权限编码
      'Permission-App': 'slm'
    }
  })
}
/**
 * 软装验收审核条件检测
 * @param {*} id
 * @returns
 */
export function getAuditCheck(id) {
  return request({
    url: `/api/v1/shopAccept/auditCheck/${id}`,
    method: 'GET'
  })
}

export function queryDecorateTask(decorationTaskCode) {
  const data = new FormData()
  data.append('pageFlag', false)
  data.append('filtersRaw', JSON.stringify([otherFiltersItem('decorationTaskCode', `[${decorationTaskCode}]`, 'in')]))
  return request({
    url: `api/v1/shopSoftwearDisplay/selectPage`,
    method: 'post',
    data
  })
}

/**
 * 修改软装陈列数据--终止数据
 * @param {*} data
 * @returns
 */
export function updateData(data) {
  return request({
    url: `/api/v1/shopSoftwearDisplay`,
    method: 'put',
    data
  })
}
